package com.rgs.base.tasks.excel;


import cn.hutool.extra.spring.SpringUtil;
import com.rgs.base.core.file.storage.FileStorageService;
import com.rgs.base.core.function.CheckFunction;
import com.rgs.base.core.page.IPageRequestModel;
import com.rgs.base.core.page.IPageResponseModel;
import com.rgs.base.core.util.excel.bo.ExcelConfigBO;

import java.util.List;

/**
 * @author Ren Gaoshuai
 * @date 2022-03-08 15:45
 **/
public class DefaultExportExcelHandle<T> extends AbstractExportExcelHandle<T> {
    private final IPageRequestModel pageRequestModel;
    private final Class<T> tClass;
    private final FileStorageService fileStorageService;
    private CheckFunction<IPageRequestModel, IPageResponseModel> readNextPage;
    private List<T> total;
    private final ExcelConfigBO excelConfig;


    public DefaultExportExcelHandle(Class<T> tClass,
                                    IPageRequestModel pageRequestModel,
                                    CheckFunction<IPageRequestModel, IPageResponseModel> readNextPage,
                                    ExcelConfigBO excelConfig) {
        this.tClass = tClass;
        this.pageRequestModel = pageRequestModel;
        this.fileStorageService = SpringUtil.getApplicationContext().getBean(FileStorageService.class);
        this.readNextPage = readNextPage;
        this.excelConfig = excelConfig;
    }

    public void setTotal(List<T> total) {
        this.total = total;
    }

    @Override
    public List<T> getTotal() {
        return total;
    }

    @Override
    public Class<T> getDestClass() {
        return tClass;
    }

    @Override
    public IPageRequestModel getPageRequestModel() {
        return this.pageRequestModel;
    }


    @Override
    public FileStorageService getFileStorageService() {
        return this.fileStorageService;
    }

    @Override
    public CheckFunction<IPageRequestModel, IPageResponseModel> getReadNextPage() {
        return this.readNextPage;
    }

    @Override
    public ExcelConfigBO getExcelConfigBO() {
        return excelConfig;
    }
}
